package com.zhaotianhao.springboot_demo_fire.test;

import com.zhaotianhao.springboot_demo_fire.entity.Firearms;
import com.zhaotianhao.springboot_demo_fire.entity.Parts;
import com.zhaotianhao.springboot_demo_fire.mapper.FirearmsRepository;
import com.zhaotianhao.springboot_demo_fire.service.IFirearmsService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @Author Z-7
 * @Date 2022/3/22
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class EStest {
    @Autowired
    private FirearmsRepository firearmsRepository;
    @Autowired
    private IFirearmsService iFirearmsService;
    @Test
    public void esAll(){
        firearmsRepository.deleteAll();
        List<Firearms> list = iFirearmsService.list();
        for (Firearms firearms : list) {
            Firearms query = iFirearmsService.queryById(firearms.getId());
            String parts = "";
            for (Parts part : query.getParts()) {
                parts += part.getName() + ",";
            }
            query.setPartsName(parts.substring(0,parts.lastIndexOf(",")));
            firearmsRepository.save(query);
        }
    }
}
